package com.kede.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kede.domain.LeescoreOrderGoodsDomain;
import com.kede.ienum.order.OrderStatusEnum;
import com.kede.mapper.LeescoreOrderGoodsMapper;
import com.kede.service.LeescoreGoodsService;
import com.kede.service.LeescoreOrderGoodsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 11856
* @description 针对表【sy_leescore_order_goods(订单-商品表)】的数据库操作Service实现
* @createDate 2023-05-15 14:16:46
*/
@Service
public class LeescoreOrderGoodsServiceImpl extends ServiceImpl<LeescoreOrderGoodsMapper, LeescoreOrderGoodsDomain>
    implements LeescoreOrderGoodsService{

    @Resource
    private LeescoreGoodsService goodsService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void backOrderGoodsByOrderId(Integer id) {
        LambdaQueryWrapper<LeescoreOrderGoodsDomain> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LeescoreOrderGoodsDomain::getOrderId,id);
        List<LeescoreOrderGoodsDomain> list = this.list(queryWrapper);
        try {
            for (LeescoreOrderGoodsDomain orderGoodsDomain : list) {
                Integer goodsId = orderGoodsDomain.getGoodsId();
                goodsService.BackStockNumById(goodsId,orderGoodsDomain.getBuyNum());
                orderGoodsDomain.setOrderStatus(OrderStatusEnum.CANCEL);
            }
            updateBatchById(list);
        }catch (Exception e){
            e.printStackTrace();

        }
    }
}




